﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ASP.Example.Routing.Controllers
{
    public class ProductController : Controller
    {
        public ActionResult Index(string category)
        {
            if (String.IsNullOrEmpty(category))
            {
                return View(new Product().Data());
            }
            else
            {
                var list = new Product().Data();
                var data = (from a in list
                            where a.CategoryName == category
                            select a).ToList();

                return View(data);
            }
        }

    }

    public class Product
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string CategoryName { get; set; }

        public List<Product> Data()
        {
            var list = new List<Product>
            {
                new Product{ID=1,Name="BMW",CategoryName="Araba"},
                new Product{ID=2,Name="Mercedes",CategoryName="Araba"},
                new Product{ID=3,Name="Audi",CategoryName="Araba"},
                new Product{ID=4,Name="Opel",CategoryName="Araba"},
                new Product{ID=5,Name="BMW",CategoryName="Motor"},
                new Product{ID=6,Name="Kawasaki",CategoryName="Motor"},
                new Product{ID=7,Name="Yamaha",CategoryName="Motor"}
            };

            return list;
        }
    }
}
